{extend name="main"}
{block name="style"}
{css href="__TEMPLATE_STATIC__/user.css"}
{/block}
{block name="header"}
{include file="module/user_top_nav"/}
{/block}
{block name="body"}
<div class="flex1 flex h-100">
	<div class="w-180px bg-dark p-4 overflow-y-auto">
	{include file="module/user/company_left" left="module/user/company_left_resume"/}
	</div>
	<div class="frame-body flex-1 overflow-y-auto py-3">
		<div class="container-xl bg-white shadow">
			<div class="flex mb-3">
				<div class="flex-1 block-title-before py-2">已下载的简历</div>
			</div>
			<div class="table-responsive">
				<el-table
					ref="multipleTable"
			      	:data="tableData"
		    		stripe
		    		v-loading="search.ajax"
		    		style="width: 100%;"
		    		header-cell-class-name="bg-1E54E5 text-666666"
    				@selection-change="handleSelectionChange">
			      <el-table-column
			        type="selection"
			        width="50">
			      </el-table-column>
				  
				 <el-table-column
			        prop="id"
			        label="ID"
			        width="100">
			      </el-table-column>
				  
			      <el-table-column
			        prop="name"
			        label="名称"
			        width="100">
				      <template slot-scope="scope">
				      	<el-link :href="'/resume/'+scope.row.resume_id+'.html'"
				      	:underline="false"
				      	target="_blank">{{scope.row.name}}</el-link>
				      </template>
			      </el-table-column>
			      <el-table-column
			        label="基本信息"
			        show-overflow-tooltip>
			        <template slot-scope="scope">
			        	{{XYBase.Date.getMStoYear(scope.row.age*1000)}}/
						<span v-if="scope.row.sex==1">男</span>
						<span v-else-if="scope.row.sex==2">女</span>
						<span v-else="scope.row.sex">未设置</span>
			        	/{{scope.row.educational_background}}/{{XYBase.Date.getMStoYear(scope.row.work_experience_time*1000)}}年经验
			        </template>
			      </el-table-column>
			      <el-table-column
			        label="筛选"
			        width="80">
			        <template slot-scope="scope">
			        	<el-tag
						    v-if="scope.row.status===0"
		        			type="info"
						    effect="plain"
						    :disable-transitions="true"
						    size="mini">
						    待支付
						</el-tag>
			        	<el-tag
						    v-else-if="scope.row.status===1"
		        			type="success"
						    effect="plain"
						    :disable-transitions="true"
						    size="mini">
						    可下载
						</el-tag>
			        </template>
			      </el-table-column>
			      <el-table-column
			        prop="create_time"
			        label="时间"
			        width="180">
			      </el-table-column>
			      <el-table-column
			        label="操作"
			        width="120">
			        <template slot-scope="scope">
			        	<el-button-group class="text-nowrap">
						  <el-button type="success" size="minism" @click="downloadsResume(scope.row);" v-if="scope.row.status === 1">下载</el-button>
						  <el-button type="info" size="minism" @click="downloadsResume(scope.row);" v-if="scope.row.status === 0">支付</el-button>
						  <el-button type="danger" size="minism" @click="delDownloadResume(scope.row,scope.$index);">删除</el-button>
						</el-button-group>
			        </template>
			      </el-table-column>
			    </el-table>
			</div>
			<div class="pt-3">
				<el-button-group class="text-nowrap">
				  <el-button type="primary" size="mini">下载</el-button>
				  <el-button type="danger" size="mini">删除</el-button>
				</el-button-group>
			</div>
			<div class="table-responsive py-3 text-center">
				<el-pagination
				  background
				  :hide-on-single-page="true"
				  @current-change="setPageChange"
			      :current-page="search.page"
			      :page-size="15"
			      layout="total,  prev, pager, next, jumper"
			      :total="search.total">
			    </el-pagination>
			</div>
		</div>
	</div>
</div>
{/block}
{block name="footer"}
{include file="module/login"/}
{include file="module/buy_win"/}
{/block}
{block name="script"}
<script type="text/javascript">
	var vm=new Vue({
		el:'#app',
		data:{
			view:XYBase.view,
			userInfo:UserInfo,
			loginTabs:XYBase.loginTabs,
			feedback:XYBase.feedback,
			buy:XYBase.buy,
			xy_score:{
				recharge_rate:{xycms:scoreconfig name="recharge_rate"},
				is_integer:{xycms:scoreconfig name="is_integer"},
				proportion:{xycms:scoreconfig name="proportion"},
			},
			search:{
		    	ajax:false,
				total:100,
				page: 1
			},
			confirm:0,
			download_resume:null,
			tableData:[],
		},
		watch:{
		    view:XYBase.viewWatch,
		    loginTabs:XYBase.loginTabsWatch,
			userInfo:{
				handler(val,oldVal){
					if (!val.id) {
						window.location.reload();
					}
				},
				deep:true
			},
		},
		created(){
			XYBase.created(this);
			this.initHtml();
		},
		methods:XYBase.methods({
			toggleSelection(rows) {
				if (rows) {
				  rows.forEach(row => {
				    this.$refs.multipleTable.toggleRowSelection(row);
				  });
				} else {
				  this.$refs.multipleTable.clearSelection();
				}
			},
			handleSelectionChange(val) {
				this.multipleSelection = val;
			},
			filterHandler(value, row, column){
		        const property = column['property'];
		        return row[property] === value;
			},
			setPageChange(val){
				this.search.page=val;
				this.initHtml();
			},
			delDownloadResume(row,index){
				var _this=this;
				_this.$confirm('确定要删除【'+row.name+'】简历吗？', '提示', {
					dangerouslyUseHTMLString:true,
		          	confirmButtonText: '确定',
		          	cancelButtonText: '取消',
		          	type: 'warning'
		        }).then(() => {
		        	_this.sendGet({
		        		url:'/user/resume/delDownloadResume/'+row.id
		        	},function(ret){
		        		if (ret) {
		        			if (ret.code === 0) {
								_this.tableData.splice(index,1);
		        			}else{
		        				XYBase.msg(ret.msg);
		        			}
		        		}
		        	});
		        }).catch(() => {
		        	XYBase.msg('已取消');
		        });
			},
			initHtml(){
				var _this=this;
				_this.search.ajax=true;
				_this.sendGet({
					url:'',
					data:_this.search,
				},function(ret){
					_this.search.ajax=false;
					if (ret) {
						_this.tableData=[];
						_this.search.total=ret.data.total;
						if (ret.code === 0) {
							_this.search.page++;
							_this.tableData=ret.data.data;
						}else XYBase.msg(ret.msg);
					}
				});
			},
			submitForm:function(formName) {
				var _this=this;
				var D=_this.form;
				_this.$refs[formName].validate((valid) => {
				  if (valid) {
					const loading = XYBase.openloading();
					_this.sendPost({
						url:url,
						data:D,
					},function(ret){
				        loading.close();
				        if (ret) {
							if(ret.code == 0){
								XYBase.success(ret.msg);
							}else{
								XYBase.msg(ret.msg);
							}
				        }
					});
				  } else {
					XYBase.warning('请先把表单填写完整。');
				    return false;
				  }
				});
			},
			openNewBuy(val){
	    		document.body.style="overflow: hidden;padding-right:17px;";
	    		this.buy.title='下载简历';
	    		this.buy.stitle='下载'+val.name+'简历';
				this.buy.pay_status='download-resume';
	    		this.buy.form.pay_type='';
	    		this.buy.form.type=11;
	    		this.buy.form.alias_id=val.id;
	    		this.buy.price=val.price;
	    		this.buy.data=val;
	    		this.buy.data.title=this.buy.title;
	    		this.buy.view=true;
				this.getScoreOrderPrice();
			},
			orderPaySuccess(val) {
				if (val.otrade===this.buy.orderInfo.otrade)
					this.buy.pay_status='success';
				if (this.buy.orderTimeEr)
					clearInterval(this.buy.orderTimeEr);
			},
			downloadsResume(row){
				var _this=this;
				const loading=XYBase.openloading();
	    		this.download_resume=row;
				_this.sendPost({
					url:'/downloads/resume/'+row.resume_id+'?confirm='+_this.confirm,
				},function(ret) {
		        	_this.confirm=0;
					loading.close();
					if (ret) {
						if (ret.code === 0) {
							if (ret.data.type=='download') {
								XYBase.success(ret.msg);
								window.open("{xycms:web name='url'}/downloads/resume/"+ret.data.id);
							}else if(ret.data.type=='pay'){
								ret.data.name=row.name;
								_this.openNewBuy(ret.data);
							}
						}else if(ret.code === 200){
							_this.$confirm(ret.msg, '提示', {
								dangerouslyUseHTMLString:true,
					          	confirmButtonText: '确定',
					          	cancelButtonText: '取消',
					          	type: 'warning'
					        }).then(() => {
					        	_this.confirm=1;
					        	_this.downloadsResume(row);
					        }).catch(() => {
					        });
						}else{
							XYBase.msg(ret.msg);
						}
					}
				});
			}
		})
	});
</script>
{/block}